var express = require('express');
var router = express.Router();
var orderApi = require('../api/orders')
const qs= require("qs")
/* GET home page. */
router.get('/', function (req, res, next) {
    res.render('index', { title: 'Express' });
});


router.get('/orderList', async function (req, res, next) {
    let lis = await orderApi.getAll();
    res.send(lis)
});

// 收藏夹路由
router.get('/listFavorite', async function (req, res, next) {
    let lis = await orderApi.getFavorite();
    res.send(lis)
});


router.delete(`/orderDel/:_id`, async function (req, res, next) {
    const {_id}=req.params;
    await orderApi.delete(_id);
    res.send("")
});

router.get("/orderFind/userId=:userId", async function (req, res, next) {
    const { userId } = req.params;
    const data = await orderApi.findId(userId);
    res.send(data);
  });

// 后台信息用
router.post(`/orderAdd`, async function (req, res, next) {
    const NewData=req.query;
    await orderApi.add(NewData);
    res.send(true);
});


router.post(`/add`, async function (req, res, next) {
  let data =  await orderApi.add(req.body);
    res.send(data);
});

module.exports = router;
